<template>
	<view class="good_detail">
		<image :src="getImgSrc(good.logo)" mode="aspectFill"></image>
		<view class="name">{{good.title}}({{good.stock}})</view>
		<!-- <view class="name">过期时间 : {{ formatDate(good.end_time) }}</view> -->
		<view class="name">过期时间 : {{ good.end_time }}</view>
		<view class="space">
			<text class="uni-icon uni-icon-location-filled" /><text v-for="item in space" :key="item.id"><text class="uni-icon uni-icon-forward"></text>{{item.title}}</text>
		</view>
		<view class="name">{{good.remark}}</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		computed: mapState(['hasLogin', 'userInfo']),
		data() {
			return {
				good : [],
				id: 0,
				space_id:0,
				space : [],
				baseUrl: getApp().globalData.baseUrl,
			}
		},
		methods: {
			getImgSrc(path){
				if(path == '' || path == null){
					return '/static/noimage.jpg'
				}else{
					return this.baseUrl + path
				}
			},
			formatDate(value) {
			        var date = new Date(value * 1000);
			        //date.setTime(value);
			        var month = date.getMonth() + 1;
			        var time = date.getFullYear() + "-" + month + "-" + date.getDate() ;
			        return time;
			},
			async getGood() {
				const res = await this.$myRequest({
					url : getApp().globalData.baseUrl + '/api.goods/goodDatils/' + this.id ,
					token : this.userInfo.token,
				})
				//console.log(res)
				this.good = res.data.data
			},
			async getSpaceKv() {
				const res = await this.$myRequest({
					url : getApp().globalData.baseUrl + '/api.space/getSpaceKv/' + this.space_id ,
					token : this.userInfo.token,
				})
				//console.log(res.data.data)
				this.space = res.data.data
			},
		},
		onLoad(options) {
			this.id = options.id
			this.space_id = options.space_id
			this.getGood()
			//console.log(this.space_id)
			this.getSpaceKv()
		}
	}
</script>

<style lang="scss">
.good_detail {
	image {
		height: 750rpx;
		width: 750rpx;
	}
	.name {
		padding: 10px;
		font-size: 35rpx;
		color: darkred;
	}
	.space {
		padding: 10px;
		font-size: 35rpx;
	}
}
</style>
